package com.example.demo;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.http.HttpRequest;

@RequestMapping("/cookie")
@RestController
public class GetCookie {

    @RequestMapping("/test1")
    public String test1(HttpServletRequest request){
        Cookie[] cookies = request.getCookies();
        if (cookies != null){
            for (Cookie cookie: cookies){
                System.out.println(cookie.getName() + ":" + cookie.getValue());
            }
            return "cookie获取成功";
        }
        return "cookie获取失败";
    }
}
